package com.woniuxy02;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Test04 {

    public static void main(String[] args) throws IOException {

        write();
        List<Student> students = read();
        System.out.println(students);
    }
    private static List<Student> read() throws IOException {
        List<Student> students=new ArrayList<>();
        BufferedReader br=new BufferedReader(new FileReader("a.txt"));
        String line;
        while((line=br.readLine())!=null){
            String[] strs = line.split(",");
            Student student=new Student(strs[0],strs[1],Integer.parseInt(strs[3]),strs[2]);
            students.add(student);
        }
        return students;
    }

    private static void write() throws IOException {
        List<Student> list = new ArrayList<Student>();
        list.add(new Student("1","zs",11,"male"));
        list.add(new Student("2","ls",12,"female"));
        list.add(new Student("3","ww",13,"male"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"));
        for(Student student: list){
            bw.write(student.getSid()+",");
            bw.write(student.getSname()+",");
            bw.write(student.getGender()+",");
            bw.write(student.getAge()+"");
            bw.newLine();
            bw.flush();
        }
        bw.close();
    }
}
